package com.sunjy.apollo1.controller;

import javax.validation.Valid;

import com.sunjy.apollo1.form.PersonForm;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.sunjy.common.annotation.BeanValid;
import com.sunjy.common.domain.ApiResponseT;
import com.sunjy.common.domain.HeaderEnum;

import lombok.extern.slf4j.Slf4j;

import com.alibaba.fastjson.JSON;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.web.bind.annotation.GetMapping;

/** 
* @author 作者 : sunjy
* @version 创建时间：2018年10月22日 下午6:14:42 
* 类说明 
*/
@RestController
@RequestMapping("hystrix")
@Slf4j
public class TestHystrixController {
	
	/**
	 * 测试被调用
	 * @return
	 */
	@BeanValid
    @GetMapping(value = "/test/{id}",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponseT<Object> test1(String name,@PathVariable("id") Integer id){
		log.info("id->{},name->{}",id,name);
		try {
			Thread.sleep(100000);
			log.info("sleep结束");
		} catch (Exception e) {
		}
		return ApiResponseT.success();
        
    }
	
	/**
	 * 测试被调用
	 * @return
	 */
	@BeanValid
    @PostMapping(value = "/test1",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponseT<Object> test2(@Valid @RequestBody PersonForm personForm, BindingResult bind){
		log.info("请求参数->{}",JSON.toJSON(personForm));
		try {
			Thread.sleep(100000);
		} catch (Exception e) {
		}
		return ApiResponseT.success();
        
    }
	
	

}
